<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <script th:src="@{/layui/layui.js}"></script>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">客户编号</label>
        <div class="layui-input-block">
            <input type="text" name="cusNo" th:value="${customer.cusNo}"  disabled="disabled" lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客户名称</label>
        <div class="layui-input-block">
            <input type="text" name="cusName" th:value="${customer.cusName}" lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户区域</label>
        <div class="layui-input-block">
            <select name="cusRegion" id="cusRegion" lay-verify="required">
                <option value="请选择"></option>
                <option value="1">东北</option>
                <option value="2">西北</option>
                <option value="3">华北</option>
                <option value="4">华东</option>
                <option value="5">华中</option>
                <option value="6">华南</option>
                <option value="7">西南</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户网址</label>
        <div class="layui-input-block">
            <input type="text" name="cusUrl" th:value="${customer.cusUrl}" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户等级</label>
        <div class="layui-input-block">
            <select name="cusLevel" id="cusLevel" lay-verify="required">
                <option value="请选择"></option>
                <option value="1">战略合作伙伴</option>
                <option value="2">VIP客户</option>
                <option value="3">大客户</option>
                <option value="4">普通客户</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">信用等级</label>
        <div class="layui-input-block">
            <select name="cusCredit" id="cusCredit" lay-verify="required">
                <option value="请选择"></option>
                <option value="1">信用极好</option>
                <option value="2">信用较好</option>
                <option value="3">信用一般</option>
                <option value="4">信用欠佳</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo2">立即提交</button>
        </div>
    </div>

</form>

<script>
    layui.use(['form', 'jquery'], function () {
        var $ = layui.jquery;
        var form = layui.form;

        //监听提交
        form.on('submit(demo2)', function (data) {
            console.log(data);
            if (form.verify()) {
                $.ajax({
                    url: "/customer/update"//规定异步提交的路径
                    , type: "POST"//规定提交的方式:POST.GET
                    , data: data.field//提交给后台的数据
                    , dataType: "json"//规定后台返回给浏览器的数据格式
                    , success: function (d) {
                        layer.msg(d.msg,{shift:-1},function () {
                            parent.table.reload("test")
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        })
                    }
                })
            }

            return false;//防止form提交刷新
        });


        //获得客户区域的值
        var cusRegionOption = [[${customer.cusRegion}]];
        var select = 'dd[lay-value=' + cusRegionOption + ']';
        $('#cusRegion').siblings("div.layui-form-select").find('dl').find(select).click()
        //获得客户等级的值

        var cusLevelOption = [[${customer.cusLevel}]];
        var select = 'dd[lay-value=' + cusLevelOption + ']';
        $('#cusLevel').siblings("div.layui-form-select").find('dl').find(select).click()
        //获得客户信用等级的值
        var cusCreditOption = [[${customer.cusCredit}]];
        var select = 'dd[lay-value=' + cusCreditOption + ']';
        $('#cusCredit').siblings("div.layui-form-select").find('dl').find(select).click()
    });

</script>


</body>
</html>